package com.erd.datacollect.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MD5Util {
    public static Logger logger= LoggerFactory.getLogger(MD5Util.class);

    public static String computeMD5Hash(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger no = new BigInteger(1, messageDigest);
            String hashtext = no.toString(16);

            // 确保摘要结果总是32位长
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (NoSuchAlgorithmException e) {
            logger.error(e.toString());
        }
        return null;
    }
    public static void main(String[] args) {
        String sign="36dcef7d72f9a12dffda17bfad759a0d";
        String app_id="1d9a42e0-9de3-451b-9964-4e9f8e62b908";
        String method="checkTicket";
        long time=new Date().getTime();
        String app_key="default_tenement";
        String requestBody="DBwx1iVugwgt0mPH7D5ARJznLt9gNvMsA48EgP9xkINb+V5PNT7lfzmmqsGjK2tOtLXxAsFQGfahm4JYzW0G+Q==";
        //md5(app_id+method+timestamp+requestBody（des 后的数据）+app_key)
        String temp = computeMD5Hash(app_id+method+time+requestBody+app_key);
        temp.equals(sign);
    }
}
